<template>
	<view>
		<uni-list>
			<uni-list-item :clickable="true" @click="onClickItem(item.id)" v-for="(item,i) in categoryList " :key="i"
				:title="item.name" note="列表描述信息" :thumb="item.img" thumb-size="lg">
			</uni-list-item>
		</uni-list>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				categoryList: [],
			}
		},

		onLoad() {
			this.loadData()
		},
		methods: {
			loadData() {
				//加载中提示
				uni.showLoading({
					title: 'loading'
				});
				// 调用接口
				uni.request({
					url: 'http://localhost:5050/category/list'
				}).then(result => {
					//加载提示消失
					uni.hideLoading();
					//控制台输出
					console.log(result.data);
					// 保存接口返回数据
					this.categoryList = result.data.data;
				}).catch(error => { //错误处理
					console.log(error)
				})
			},

			onClickItem(id) {
				uni.navigateTo({
					url: '/pages/goodsList/goodsList?categoryId=' + id
				})
			}


		}
	}
</script>

<style>

</style>